package com.pool.activity;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;

/**
 * {@link Handler} for the {@link LoginAndRun} activity UI.
 * 
 * @author claveld@gmail.com (David Clavel)
 */
public class LoginAndRunHandler extends Handler {

  private static final String COMMAND = "command";
  private static final String VALUE = "value";

  private static final String SHOW_DIALOG = "show_dialog";
  
  private final Activity activity;

  public LoginAndRunHandler(Activity activity) {
    this.activity = activity;
  }
  
  @Override
  public void handleMessage(Message msg) {
    String command = msg.getData().getString(COMMAND);
    if (SHOW_DIALOG.equals(command)) {
      int dialogId = Integer.parseInt(msg.getData().getString(VALUE));
      activity.showDialog(dialogId);
    }
  }
  
  public void showDialog(int dialogId) {
    sendCommand(SHOW_DIALOG, Integer.toString(dialogId));
  }
  
  private void sendCommand(String command, String value) {
    Message message = new Message();
    message.getData().putString(COMMAND, command);
    message.getData().putString(VALUE, value);
    sendMessage(message);
  }
}
